/**
 * This file is part of 1genia trampoline
 * Copyright (C) 2007-2008 1genia (contact@1genia.com)
 *
 * This library is free software; you can redistribute it and/or modify
 * it under the terms of the GNU Lesser General Public License as
 * published by the Free Software Foundation; version 3 of the License. 
 *
 * This library is distributed in the hope that it will be useful, but
 * WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Library General Public License for more details. 
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; see the file COPYING.TXT.  If not,
 * write to the Free Software Foundation, Inc., 51 Franklin Street,
 * Fifth Floor, Boston, MA 02110-1301, USA. 
 **/
package com.genia.toolbox.projects.toolbox_basics_project.web.taglib;

import com.genia.toolbox.persistence.exception.PersistenceException;
import com.genia.toolbox.projects.toolbox_basics_project.bean.ApplicationParameter;
import com.genia.toolbox.projects.toolbox_basics_project.bean.model.I18nDynamicValue;
import com.genia.toolbox.projects.toolbox_basics_project.spring.manager.I18nDynamicEntityManager;
import com.genia.toolbox.projects.toolbox_basics_project.spring.manager.ParameterManager;

/**
 * The spring bean containing the actuals functions for JSTL.
 */
public class SpringFunctions
{

  /**
   * the {@link I18nDynamicEntityManager}.
   */
  private I18nDynamicEntityManager i18DynamicEntityManager;

  /**
   * the {@link ParameterManager} to use.
   */
  private ParameterManager parameterManager;



  /**
   * translate a {@link I18nDynamicValue} in the current language.
   * 
   * @param value
   *          the value to translate
   * @return the translated value
   * @throws PersistenceException
   *           when an error occured
   */
  public String translate(I18nDynamicValue value)
      throws PersistenceException
  {
    return getI18DynamicEntityManager().getTranslation(value);
  }



  /**
   * returns the current value of the parameter with the reference name given in
   * parameter.
   * 
   * @param parameterName
   *          the name of the parameter
   * @return the current value of the parameter with the reference name given in
   *         parameter
   */
  public Object getParameter(String parameterName)
  {
    ApplicationParameter<?> applicationParameter = getParameterManager().getApplicationParameter(parameterName);
    if (applicationParameter == null) {
      return null;
    }
    return applicationParameter.getValue();
  }



  /**
   * getter for the i18DynamicEntityManager property.
   * 
   * @return the i18DynamicEntityManager
   */
  public I18nDynamicEntityManager getI18DynamicEntityManager()
  {
    return i18DynamicEntityManager;
  }



  /**
   * setter for the i18DynamicEntityManager property.
   * 
   * @param dynamicEntityManager
   *          the i18DynamicEntityManager to set
   */
  public void setI18DynamicEntityManager(I18nDynamicEntityManager dynamicEntityManager)
  {
    i18DynamicEntityManager = dynamicEntityManager;
  }



  /**
   * getter for the parameterManager property.
   * 
   * @return the parameterManager
   */
  public ParameterManager getParameterManager()
  {
    return parameterManager;
  }



  /**
   * setter for the parameterManager property.
   * 
   * @param parameterManager
   *          the parameterManager to set
   */
  public void setParameterManager(ParameterManager parameterManager)
  {
    this.parameterManager = parameterManager;
  }

}
